package com.uls.web.controller.zsw;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.uls.czj.service.ICzjStudentsService;
import com.uls.zsw.domain.StudentVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.zsw.domain.DormitoryInfo;
import com.uls.zsw.service.IDormitoryInfoService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 宿舍信息Controller
 * 
 * @author zsw
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/zsw/dormitory_info")
public class DormitoryInfoController extends BaseController
{
    @Autowired
    private IDormitoryInfoService dormitoryInfoService;

    /**
     * 查询宿舍信息列表
     */
    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:list')")
    @GetMapping("/list")
    public TableDataInfo list(DormitoryInfo dormitoryInfo)
    {
        startPage();
        List<DormitoryInfo> list = dormitoryInfoService.selectDormitoryInfoList(dormitoryInfo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:dnlist')")
    @GetMapping("/dnlist")
    public AjaxResult dnlist(){
        List<String> dnlist=dormitoryInfoService.selectAllDormitoryNumber();
        System.out.println(dnlist);
        return success(dnlist);
    }

    /**
     * 导出宿舍信息列表
     */
    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:export')")
    @Log(title = "宿舍信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DormitoryInfo dormitoryInfo)
    {
        List<DormitoryInfo> list = dormitoryInfoService.selectDormitoryInfoList(dormitoryInfo);
        ExcelUtil<DormitoryInfo> util = new ExcelUtil<DormitoryInfo>(DormitoryInfo.class);
        util.exportExcel(response, list, "宿舍信息数据");
    }

    /**
     * 获取宿舍信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:query')")
    @GetMapping(value = "/{dormitoryId}")
    public AjaxResult getInfo(@PathVariable("dormitoryId") Long dormitoryId)
    {
        return success(dormitoryInfoService.selectDormitoryInfoByDormitoryId(dormitoryId));
    }

    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:findstudent')")
    @GetMapping(value = "/getstudent/{studentNumber}")
    public AjaxResult findstudentbystudentNumber(@PathVariable("studentNumber") Long studentNumber){
        System.out.println(studentNumber);
        StudentVo studentVo=dormitoryInfoService.findStudentByStudentNumber(studentNumber);
        System.out.println(studentVo);
        return success(dormitoryInfoService.findStudentByStudentNumber(studentNumber));
    }
    /**
     * 新增宿舍信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:add')")
    @Log(title = "宿舍信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DormitoryInfo dormitoryInfo)
    {
        return toAjax(dormitoryInfoService.insertDormitoryInfo(dormitoryInfo));
    }

    /**
     * 修改宿舍信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:edit')")
    @Log(title = "宿舍信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DormitoryInfo dormitoryInfo)
    {
        return toAjax(dormitoryInfoService.updateDormitoryInfo(dormitoryInfo));
    }

    /**
     * 删除宿舍信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:remove')")
    @Log(title = "宿舍信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dormitoryIds}")
    public AjaxResult remove(@PathVariable Long[] dormitoryIds)
    {
        return toAjax(dormitoryInfoService.deleteDormitoryInfoByDormitoryIds(dormitoryIds));
    }

    @PreAuthorize("@ss.hasPermi('zsw:dormitory_info:delindormitory')")
    @RequestMapping("/delindormitory/{studentIds}")
    public void delindormitory(@PathVariable Long[] studentIds){
        dormitoryInfoService.delStudentinDormitory(studentIds);
    }
}
